/**
 * 手写call
 */

function _call(context) {
    context = context || window

    const symbol = Symbol('fn')
    context[symbol] = this

    let res = context[symbol]([...arguments].slice(1))

    delete context[symbol]

    return res;
}

function _apply(context) {
    context = context || window
    const symbol = Symbol('fn')
    context[symbol] = this

    let res = context[symbol]([...arguments][1])
    delete context[symbol]

    return res;
}

function _bind(context) {
    context = context || window
    const symbol = Symbol('fn')
    context[symbol] = this

    let res = function () {
        return context[symbol]([...arguments].slice(1))
    }
    delete context[symbol];
    return res;
}


Function.prototype._call = function (context = window) {
  const args = [...arguments].slice(1);
  context.fn = this;

  const res = context.fn(...args);
  // apply
  // const res = context.fn(args);
  delete context.fn;
  return res;
};

Function.prototype._bind = function (context = window) {
  const _args = [...arguments].slice(1);
  context.fn = this;

  return function (...args) {
    const arg = [..._args, ...args];
    context.fn(arg);

    delete context.fn;
  };
};